//
//  HeightViewController.m
//  Light
//
//  Created by 骁唐 on 15/9/6.
//  Copyright (c) 2015年 骁唐. All rights reserved.
//

#import "HeightViewController.h"
#import "UserConfig.h"

@interface HeightViewController ()
@property (weak, nonatomic) IBOutlet UIPickerView *heightPickerview;
@property (strong,nonatomic) NSMutableArray *cmArray;
//当前高
@property (copy,nonatomic) NSString *height;
@property (weak, nonatomic) IBOutlet UIImageView *backGround;

@end

@implementation HeightViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.height = @"70";
    self.cmArray = [[NSMutableArray alloc]init];
    // Do any additional setup after loading the view.
    for  (int i = 0; i< 100; i++) {
        [self.cmArray addObject:[NSString stringWithFormat:@"%d",i]];
    }
    //设置默认在compoent列中默认选中row行
    [self.heightPickerview selectRow:70 inComponent:0 animated:YES];
}

-(NSInteger) numberOfComponentsInPickerView:(UIPickerView *)pickerView{
 //   NSLog(@"调用%s ,%d",__FUNCTION__,__LINE__);
    //返回有几列 ，注意
    return 1;
}

//返回指定列的行数
- (NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
   // NSLog(@"调用%s ,%d",__FUNCTION__,__LINE__);
    
   // NSLog(@"列数%lu",(unsigned long)[self.cmArray count]);
    
        return  [self.cmArray count];
}

//以下是代理部分，可以自定义视图
//返回指定列，行的高度，就是自定义行的高度
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component{
  //  NSLog(@"调用%s ,%d",__FUNCTION__,__LINE__);
    return  60;
}

//返回指定列的宽度
- (CGFloat) pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component{
  //  NSLog(@"调用%s ,%d",__FUNCTION__,__LINE__);
    return 80;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    
  //  NSLog(@"调用%s ,%d",__FUNCTION__,__LINE__);
    //思想就是：先创建一个View以指定列的宽度，和所在列行的高度，为尺寸
    //再建立一个label,在这个view上显示字体，字体颜色，字体大小，然后，把这个label添加到view中
    //返回view，作为指定列的每行的视图
    //取得指定列的宽度
    CGFloat width=[self pickerView:pickerView widthForComponent:component];
    //取得指定列，行的高度
    CGFloat height=[self pickerView:pickerView rowHeightForComponent:component];
    //定义一个视图
    UIView *myView=[[UIView alloc] init];
    //指定视图frame
    myView.frame=CGRectMake(0, 0, width, height);
    myView.backgroundColor = [UIColor clearColor];
    UILabel *labelOnComponent=[[UILabel alloc] init];
    labelOnComponent.frame=myView.frame;
    labelOnComponent.tag=200;
      
    //在label上显示改字体
    labelOnComponent.text= [self.cmArray objectAtIndex:row];
    labelOnComponent.textColor = [UIColor whiteColor];
    labelOnComponent.textAlignment = UIBaselineAdjustmentAlignCenters;
    [labelOnComponent setNumberOfLines:0];
    labelOnComponent.font = [UIFont fontWithName:@"Helvetica" size:35];
    labelOnComponent.adjustsFontSizeToFitWidth = YES;
    [myView addSubview:labelOnComponent];
    return myView;
}

- (void)pickerView:(UIPickerView *)pickerView
      didSelectRow:(NSInteger)row
       inComponent:(NSInteger)component
{
    if (0 == component) {
        self.height = self.cmArray[row];
    }
}

#pragma mark -
#pragma mark 导航返回按钮
- (IBAction)backClick {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -
#pragma mark 进入下一个界面
- (IBAction)nextClick {
    UserConfig  *userConfig = [UserConfig sharingUserConfig];
    NSString *heightStr = [NSString stringWithFormat:@"1%@",self.height];
    [userConfig setCurrentHeight:[NSString stringWithFormat:@"%@",heightStr]];
    [self performSegueWithIdentifier:@"HeightToWeight" sender:nil];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //强制竖屏
    [[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:
                                        UIInterfaceOrientationPortrait]  forKey:@"orientation"];
    long long int currentTimeInt = [TJJDefines getTimeIntSince1970Current];
    if (currentTimeInt>=16200&& currentTimeInt <=34200) {
        self.backGround.image = [UIImage imageNamed:@"backgroundOne"];
    }else if (currentTimeInt>34200 && currentTimeInt<=55800)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundTwo"];
    }else if (currentTimeInt>55800 && currentTimeInt<=70200)
    {
        self.backGround.image = [UIImage imageNamed:@"backgroundThree"];
    }else if(currentTimeInt >70200 || currentTimeInt<16200)
    {
        self.backGround.image = [UIImage imageNamed:@"background_night"];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */
@end
